/**
 * 
 */
package org.vsg.common.pagination.wrapper;

import java.util.Collection;

import org.vsg.common.pagination.Pagination;

/**
 * @author Bill Vison
 *
 */
public abstract class AbstractPaginationWrapper implements PaginationWrapper {
	
	private Pagination pagination;

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#loadPagination(org.vsg.commons.util.pagination.Pagination)
	 */
	public void loadPagination(Pagination pagination)
			throws PaginationWrapperException {
		// TODO Auto-generated method stub
		this.pagination = pagination;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getTotalRecord()
	 */
	public int getTotalRecord() {
		// TODO Auto-generated method stub
		return this.pagination.getTotalRecord();
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getPaginationList()
	 */
	public Collection getPaginationList() {
		// TODO Auto-generated method stub
		return this.pagination.getPaginationList();
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getTotalPages()
	 */
	public int getTotalPages() {
		// TODO Auto-generated method stub
		return this.pagination.getTotalPages();
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getLastPage()
	 */
	public int getLastPage() {
		// TODO Auto-generated method stub
		return this.pagination.getLastPageIndex();
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getFirstPage()
	 */
	public int getFirstPage() {
		// TODO Auto-generated method stub
		return this.pagination.getFirstPageIndex();
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getPrevPage()
	 */
	public int getPrevPage() {
		// TODO Auto-generated method stub
		int prevPage = 0;
		if (this.pagination.getTotalRecord() > 0) {
			
			prevPage = this.pagination.getPageIndex() - 1;
			if (prevPage < 0) {
				prevPage = this.pagination.getFirstPageIndex();
			}
		}
		return prevPage;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getNextPage()
	 */
	public int getNextPage() {
		// TODO Auto-generated method stub
		int nextPage = 0;
		if (this.pagination.getTotalRecord() > 0) {
			nextPage =  this.pagination.getPageIndex() + 1;
			
			if (nextPage > this.pagination.getLastPageIndex()) {
				nextPage = this.pagination.getLastPageIndex();
			}
		}
		return nextPage;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.wrapper.PaginationWrapper#getCurrentPage()
	 */
	public int getCurrentPage() {
		// TODO Auto-generated method stub
		return this.pagination.getPageIndex();
	}

	/**
	 * @return Returns the pagination.
	 */
	public Pagination getPagination() {
		return pagination;
	}
	
	

}
